<?php namespace testsacvoyage\domain;

require_once 'sacvoyage/Object.php';
use \sacvoyage\Object;

require_once 'sacvoyage/domain/Domain.php';
use \sacvoyage\domain\Domain;

require_once 'sacvoyage/storage/Storage.php';
use \sacvoyage\storage\Storage;


require_once 'AbstractTest.php';

class DomainTest extends AbstractTest {
	
	public function setUp() {
		$this->resetDatabase();
		$this->_domain=new Domain($this->getStorage());
		
		// write user
		$root=$this->_domain->loadUser('root');
		$sys_users=$root->getProperty()->getCollection('sys.user.accounts');
		$sys_users->write(array(new Object(array(
			'_id'=>'alex', 
			'password'=>'123'
		))));
		
		$notes=$this->_domain->loadUser('alex')->getProperty()->getCollection('db.notes');
		$notes->write(array(new Object(array(
			'_id'=>'alexnote',
			'text'=>'не забыть эээ... ммм... Черт, забыл'
		))));
		
	}
	
	public function testLogin() {
		$this->assertNotNull($this->_domain->login('alex', '123'));
		$this->assertNull($this->_domain->login('alex', '1234'));
		$this->assertNull($this->_domain->login('alex', ''));
		$this->assertNull($this->_domain->login('vova', '123'));
	}
	
	public function testProperty() {
		$note=$this->_domain->login('alex', '123')
		          ->getProperty()->getCollection('db.notes')->read('alexnote');
		$this->assertEquals(
			'не забыть эээ... ммм... Черт, забыл',
			$note->text
		);
	}	
	
	
	
}



?>